<!DOCTYPE html>
<html lang="zn">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="../js/vue.js"></script>
  <title>基本列表</title>
</head>

<body>
  <!-- 
    v-for指令:
      1.用于展示列表数据
      2.语法:v-for="(item,index) in xxx" :key="yyy"
      3.可遍历:数组,对象,字符串,指定次数
   -->
  <div id="root">
    <!-- 遍历数组 -->
    <h2>人员列表</h2>
    <ul>
      <li v-for="person in personList" :key="person.id">
        {{person.name}}-{{person.age}}
      </li>
    </ul>
    <h2>人员列表</h2>
    <ul>
      <li v-for="(person,index) in personList" :key="index">
        {{person.name}}-{{person.age}}-{{index}}
      </li>
    </ul>

    <!-- 遍历对象 -->
    <h2>汽车信息</h2>
    <ul>
      <li v-for="(car,index) of carInfo" :key="index">
        {{car}}-{{index}}
      </li>
    </ul>

    <!-- 遍历字符串 -->
    <h2>遍历字符串</h2>
    <ul>
      <li v-for="(a,index) in str" :key="index">
        {{a}}--{{index}}
      </li>
    </ul>

    <!-- 遍历指定次数 -->
    <h2>遍历指定次数</h2>
    <ul>
      <li v-for="(a,b) in 6" :key="b">
        {{a}}--{{b}}
      </li>
    </ul>

  </div>

  <script>
    Vue.config.productionTip = false

    new Vue({
      el: '#root',
      data() {
        return {
          personList: [
            {
              id: '001',
              name: '张三',
              age: 25
            },
            {
              id: '002',
              name: '李四',
              age: 26
            },
            {
              id: '003',
              name: '王五',
              age: 27
            },
          ],
          carInfo:{
            brand:'奇瑞艾瑞泽8',
            price:120000,
            color:'黑色'
          },
          str:'hello'
        }
      },
    })
  </script>
</body>

</html>